package com.heima.controller;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.RegionDTO;
import com.heima.pojo.vo.RegionVO;
import com.heima.result.PageResult;
import com.heima.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/vm-service/region")
public class RegionController {
    @Autowired
    RegionService regionService;

    /**
     * 添加区域
     * @param dto
     * @return
     */

    @PostMapping
    public Boolean add(@RequestBody RegionDTO dto) {
        Boolean result = regionService.add(dto);
        return result;
    }

    /**
     * 查询
     * @param dto
     * @return
     */
    @GetMapping("/search")
    public PageResult<RegionVO> pageQuery(PageQueryDTO dto) {
        PageResult<RegionVO> page = regionService.pageQuery(dto);
        return page;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Long id) {
        Boolean result = regionService.delete(id);
        return result;
    }

    /**
     * 修改区域
     * @param id
     * @param dto
     * @return
     */
    @PutMapping("/{id}")
    public Boolean update(@PathVariable Long id,@RequestBody RegionDTO dto) {
        Boolean result = regionService.update(id, dto);
        return result;
    }
}
